/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cannes.dao.implement;

import cannes.bean.planning.Salle;
import cannes.connexion.ConnexionBDD;
import cannes.dao.DAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author p1000666
 */
public class SalleDAO extends DAO<Salle> {

    public SalleDAO(Connection conn) {
        super(conn);
    }

    @Override
    public boolean create(Salle obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Salle obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean delete(Salle obj) {
        
        try {
            ResultSet result = this.connect.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY).executeQuery(
                    "DELETE FROM salle WHERE salleid = " + obj.getId());
            result.rowDeleted();

        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        return false;
    }

    @Override
    public int next() {
        throw new UnsupportedOperationException("Not supported yet.");
    }



    @Override
    public Salle find(int id) {
        Salle salle = new Salle();

        try {
            ResultSet result = this.connect.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY).executeQuery(
                    "SELECT * FROM salle WHERE salleid = " + id);
            if (result.first()) {
                salle = new Salle(result.getInt("salleid"), result.getString("nom"),
                        result.getInt("capacite"), result.getString("adresse"),
                        result.getString("description"));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return salle;

    }

    @Override
    public ArrayList<Salle> findAll() {
                
        ArrayList<Salle> listeSalle = new ArrayList<Salle>();
        
        try {
            ResultSet result = this.connect.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY).executeQuery(
                    "SELECT * FROM salle");
            while(result.next()){
                listeSalle.add(new Salle(result.getInt("salleid"), result.getString("nom"),
                        result.getInt("capacite"), result.getString("adresse"),
                        result.getString("description")));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        return listeSalle;
        
    }
}
